<?
	Class Aerodrome extends Database {

		private $title;
		private $code;
		private $location;
		private $runways;
		private $weather;
		private $frequencies;

		public function __get($property) {
			return $this->$property;
		}

		public function __set($property, $value) {
			$this->$property = $value;
		}

		public function getRunways($handler) {
			// collect runways
			$runways = array();
			// fetch runways
			$query = "SELECT * from runways WHERE airport_ident ='" . $this->code . "' ORDER BY length_ft DESC;";
			// populate runway data
			// TODO: fix this shit
		    $Database = new Database();
		    $Database->init();
		    $handler = $Database->handler;	
			if ($result = $handler->query($query, MYSQLI_USE_RESULT)) {
		        while($row = $result->fetch_row()) { 
		        	// New runway
					$runway = new Runway();
					$runway->length_ft = $row[2];
					$runway->width_ft = $row[3];
					$runway->surface = $row[4];
					$runway->lighted = $row[5];
					$runway->le_ident = $row[6];
					$runway->le_latitude_deg = $row[7];
					$runway->le_longitude_deg = $row[8];
					$runway->le_elevation_ft = $row[9];
					$runway->le_heading_degT = $row[10];
					$runway->le_displaced_threshold_ft = $row[11];
					$runway->he_ident = $row[12];
					$runway->he_latitude_deg = $row[13];
					$runway->he_longitude_deg = $row[14];
					$runway->he_elevation_ft = $row[15];
					$runway->he_heading_degT = $row[16];
					$runway->he_displaced_threshold_ft = $row[17];
					$runways[] = $runway;
		        }
		    }
		    $this->runways = $runways;
		}

		public function getFrequencies() {
			// collect frequencies
			$frequencies = array();
			// fetch frequencies
			$query = "SELECT * from frequencies WHERE airport_ident ='" . $this->code . "'";
			// populate freq data
			// TODO: fix this shit
		    $Database = new Database();
		    $Database->init();
		    $handler = $Database->handler;	
			if ($result = $handler->query($query, MYSQLI_USE_RESULT)) {
		        while($row = $result->fetch_row()) { 
		        	// New frequency
					$frequency = new Frequency();
					$frequency->type = $row[2];
					$frequency->description = $row[3];
					$frequency->frequency_mhz = $row[4];
					$frequencies[] = $frequency;
		        }
		    }
		    $this->frequencies = $frequencies;
		}

		public function getMetars() {

		}

		public function getLongestRunway() {
			$longest = 0;
			foreach ($this->runways as $key => $value) {
				if ($value->length_ft > $longest) $longest = $value->length_ft;
			}
			return $longest;
		}

		public function checkScale() {
			//if ($this->runways)
		}

	}
?>